<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教师评价</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
</head>
<body>

<div>
    <form class="layui-form">
        <div class="layui-inline">
            <label class="layui-form-label">名字</label>
            <div class="layui-input-inline">
                <input type="text" id="name" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <input type="button" id="search" value="查询"  autocomplete="off" class="layui-btn">
            </div>
        </div>
    </form>

</div>
<table id="demo" lay-filter="test"></table>

<script src="https://www.layuicdn.com/layui/layui.js"></script>
<script>
    layui.use(['table', 'layer','jquery'], function () {
        var table = layui.table;
        var layer = layui.layer;
        let $ = layui.jquery;

        table.render({
            elem: '#demo',
            height: 'auto',
            url: '/teacher/getTeacherEvaluates', //数据接口,
            page: true, //开启分页
            cols: [[ //表头
                {field: 'teacherName', title: '教师姓名', width: "20%"},
                {field: 'studentId', title: '学生学号', width: "20%"},
                {field: 'studentName', title: '学生姓名', width: "20%"},
                {field: 'evaluateScore', title: '评价评分', width: "20%",templet:function (data) {
                        if (!data.evaluateScore){
                            return '未评价';
                        }else return data.evaluateScore;
                    }},
                { title: '操作', width: "20%",templet(data){
                    let role = '${sessionScope.role}'
                        if (role==='2'){
                            // 教师
                            return '';
                        }else if (!data.evaluateScore){
                            // 需要打分
                            return '<a lay-event="evaluation" class="layui-btn layui-btn-xs">评价</a>'
                        }else {
                            // 不需要打分
                            return ''
                        }
                    }},
            ]],
            response: {
                statusCode: 200 ,//规定成功的状态码，默认：0
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
        });

        table.on('tool(test)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if(layEvent === 'evaluation') {
                layer.open({
                    type:2,
                    content:'/teacher/evaluationRate',
                    success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        body.find("#teacherId").val(data.teacherId);
                        body.find("#evaluateId").val(data.evaluateId);
                    }

                })
            }
        })

    })
</script>
</body>
</html>